package com.example.api.service.impl;

import com.example.api.dao.DriverDao;
import com.example.api.model.constants.LogisticsConstants;
import com.example.api.model.entity.Driver;
import com.example.api.model.support.RespBean;
import com.example.api.service.DriverService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DriverServiceImpl implements DriverService {

    @Resource
    private DriverDao driverDao;

    @Override
    public RespBean save(Driver driver) {
        driver.setDriving(LogisticsConstants.DRIVER_DRIVING_1);
        driver.setCreateTime(new Date());
        if (driverDao.insertSelective(driver) > 0) {
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @Override
    public RespBean update(Driver driver) {
        driver.setUpdateTime(new Date());
        if (driverDao.updateByPrimaryKeySelective(driver) > 0) {
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }

    @Override
    public RespBean delete(Integer id) {
        if (driverDao.deleteByPrimaryKey(id) > 0) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @Override
    public Driver findById(Integer id) {
        return driverDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Driver> findAll(String name) {
        return driverDao.findAll(name);
    }

}